using Framework.DataTable;
using System.Collections.Generic;
public partial class SampleTable : DataTableLoader<SampleData>
{
    public override string GetTableName() { return "Sample"; }
    protected override SampleData CreateItem()
    {
        return new SampleData();
    }
    public SampleTable()
    {
        _branchs = new List<string>() { "ch", "en" };
    }
#if true
    private Dictionary<string, int> _keyToIndex;
    protected override void BuildIndex()
    {
        base.BuildIndex();
        if (_keyToIndex == null)
        {
            _keyToIndex = new Dictionary<string, int>(ItemCount);
        }
        else
        {
            _keyToIndex.Clear();
        }
        var len = DataList.Count;
        for (int i = 0; i < len; i++)
        {
            var item = DataList[i];
            if (item == null)
            {
                break;
            }
            if (_keyToIndex.ContainsKey(item.Id))
            {
                UnityEngine.Debug.LogErrorFormat("{0} 存在相同的索引 {1}", FileName, item.Id);
                continue;
            }
            _keyToIndex.Add(item.Id, i);
        }
    }
    public SampleData Get(string key)
    {
        if (_keyToIndex != null && _keyToIndex.TryGetValue(key, out int index))
        {
            return GetItem(index);
        }
        return null;
    }
#endif
}
public partial class SampleData
{
    public string Id { get; protected set; }
    /// <summary>
    ///名字
    /// </summary>
    public string Name { get; protected set; }
    public CState State { get; protected set; }
    public int[] PList { get; protected set; }
    public UnityEngine.Vector3[] PosList { get; protected set; }
    public string Text { get; protected set; }
}
public partial class SampleData : IDataTable
{
    public virtual void Decode(Framework.ByteArray buffer)
    {
        Id = buffer.ReadString();
        Name = buffer.ReadString();
        State = (CState)buffer.ReadInt();
        PList = new int[buffer.ReadUshort()]; for (var i = 0; i < PList.Length; i++) { PList[i] = buffer.ReadInt(); }
        PosList = new UnityEngine.Vector3[buffer.ReadUshort()]; for (var i = 0; i < PosList.Length; i++) { PosList[i] = Vector3Ext.Decode(buffer); }
        Text = buffer.ReadString();
    }
}
#if UNITY_EDITOR
public partial class SampleData : IDataTable
{
	public void Parse(string[] values)
	{
        Id = values[0];
        Name = values[1];
        State = (CState)Framework.Utils.Parse.ParseInt(values[2]);
        if (Framework.Utils.Parse.ParseList(values[3]) is string[] s_PList) { PList = new int[s_PList.Length]; for (int i = 0; i < s_PList.Length; i++) { PList[i] = Framework.Utils.Parse.ParseInt(s_PList[i]); } }
        if (Framework.Utils.Parse.ParseList(values[4]) is string[] s_PosList) { PosList = new UnityEngine.Vector3[s_PosList.Length]; for (int i = 0; i < s_PosList.Length; i++) { PosList[i] = Vector3Ext.DeserializeObject(s_PosList[i]); } }
        Text = values[5];
	}
    public void Encode(Framework.ByteArray buffer)
    {
        buffer.Write(Id);
        buffer.Write(Name);
        buffer.Write((int)State);
        if (PList != null) { buffer.Write((ushort)PList.Length); for (var i = 0; i < (ushort)PList.Length; i++) { buffer.Write(PList[i]); } } else { buffer.Write((ushort)0); }
        if (PosList != null) { buffer.Write((ushort)PosList.Length); for (var i = 0; i < (ushort)PosList.Length; i++) { Vector3Ext.Encode(PosList[i], buffer); } } else { buffer.Write((ushort)0); }
        buffer.Write(Text);
    }
}
#endif